<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/3/18
 * Time: 8:24
 */
namespace app\api\controller;
use think\Db;
use think\Request;
class WxRefundNotify
{
    public  function __construct($str, $key) {
        $result = json_decode($str, true);//转成数组，
        file_put_contents('666.php',$result);
        if($result['return_code']=='SUCCESS'){
            $key=strtolower(MD5($key));
            $decrypt = base64_decode($result['req_info'], true);
            $this->xmlToArray(openssl_decrypt($decrypt , 'aes-256-ecb', $key, OPENSSL_RAW_DATA));
        }else{
            return false;
        }
    }
    public function xmlToArray($xml) {
        $jsonxml = json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA));
        $result = json_decode($jsonxml, true);
        return $result;
    }

}
